#!/bin/bash

version="1.0"
projectName=""

funGetVersion(){
	dirPath=$1
	jarName=$(find $dirPath -name *.jar)
	versionStr=${jarName%-*}
	version=${versionStr##*-}
	if [ ${#version} -eq 0 ]
	then
		version="1.0"
	fi
}


for dockerFile in `find . -name Dockerfile`
do
  echo $dockerFile

  projectNameStr=${dockerFile#*/}
  projectName=${projectNameStr%%/*}
  dirPath=${dockerFile%/*}

  funGetVersion $dirPath

  dockerfileTag=${projectName}':'${version}
  #build dockerfile
  #echo $dockerfileTag-$dockerFile-$dirPath
  docker build -t $dockerfileTag -f $dockerFile $dirPath
  docker tag $dockerfileTag 192.168.38.120:81/mall4j/$dockerfileTag
  docker login 192.168.38.120:81 -u admin -p Harbor12345
  docker push 192.168.38.120:81/mall4j/$dockerfileTag

done
